package com.cskaoyan.util.ad;

import com.cskaoyan.bean.admin.promotion.bo.AdBo;
import com.cskaoyan.bean.admin.promotion.bo.CouponBo;
import com.cskaoyan.bean.admin.promotion.bo.GrouponRulesBo;
import com.cskaoyan.bean.admin.promotion.bo.TopicBo;
import com.cskaoyan.bean.admin.promotion.vo.*;
import com.cskaoyan.bean.pojo.*;
import com.cskaoyan.bean.wx.catalog.vo.CatalogVo;
import com.cskaoyan.mapper.CouponMapper;

import java.lang.System;
import java.util.Date;
import java.util.List;

/**
 * @Name : TopicController.java
 * @Time : 2021/8/12 19:36
 * @Author : creamycandy
 * @Software : IntelliJ IDEA
 */
public class TransferUtils {

    public static ItemsBean Ad2Bo(Ad ad) {
        ItemsBean itemsBean = new ItemsBean();
        itemsBean.setId(ad.getId());
        itemsBean.setName(ad.getName());
        itemsBean.setLink(ad.getLink());
        itemsBean.setUrl(ad.getUrl());
        itemsBean.setPosition(ad.getPosition());
        itemsBean.setContent(ad.getContent());
        itemsBean.setEnabled(ad.getEnabled());
        itemsBean.setAddTime(ad.getAddTime());
        itemsBean.setUpdateTime(ad.getUpdateTime());
        itemsBean.setDeleted(ad.getDeleted());
        return itemsBean;
    }

    public static Ad Vo2Ad(AdBo adBo) {
        Ad ad = new Ad();
        ad.setId(adBo.getId());
        ad.setName(adBo.getName());
        ad.setLink(adBo.getLink());
        ad.setUrl(adBo.getUrl());
        ad.setPosition(adBo.getPosition());
        ad.setContent(adBo.getContent());
        ad.setEnabled(adBo.getEnabled());
        ad.setAddTime(adBo.getAddTime());
        ad.setUpdateTime(adBo.getUpdateTime());
        ad.setDeleted(adBo.getDeleted());
        return ad;
    }

    public static CouponVo Coupon2CouponVo(Coupon coupon){
        CouponVo couponVo = new CouponVo();
        couponVo.setId(coupon.getId());
        couponVo.setName(coupon.getName());
        couponVo.setDesc(coupon.getDesc());
        couponVo.setTag(coupon.getTag());
        couponVo.setTotal(coupon.getTotal());
        couponVo.setDiscount(coupon.getDiscount());
        couponVo.setMin(coupon.getMin());
        couponVo.setLimit(coupon.getLimit());
        couponVo.setType(coupon.getType());
        couponVo.setStatus(coupon.getStatus());
        couponVo.setGoodsType(coupon.getGoodsType());
        couponVo.setTimeType(coupon.getTimeType());
        couponVo.setDays(coupon.getDays());
        couponVo.setCode(coupon.getCode());
        couponVo.setStartTime(coupon.getStartTime());
        couponVo.setEndTime(coupon.getEndTime());
        couponVo.setAddTime(coupon.getAddTime());
        couponVo.setUpdateTime(coupon.getUpdateTime());
        couponVo.setDeleted(coupon.getDeleted());
        couponVo.setGoodsValue(coupon.getGoodsValue());
        return couponVo;
    }

    public static Coupon CouponBo2Coupon(CouponBo couponBo, CouponMapper couponMapper){
        Coupon coupon = new Coupon();
        coupon.setName(couponBo.getName());
        coupon.setDesc(couponBo.getDesc());
        coupon.setTag(couponBo.getTag());
        coupon.setTotal(couponBo.getTotal());
        coupon.setDiscount(couponBo.getDiscount());
        coupon.setMin(couponBo.getMin());
        coupon.setLimit(couponBo.getLimit());
        coupon.setType(couponBo.getType());
        coupon.setStatus(couponBo.getStatus());
        coupon.setGoodsType(couponBo.getGoodsType());
        coupon.setGoodsValue(couponBo.getGoodsValue());
        if(coupon.getType()==2){
            CouponExample couponExample = new CouponExample();
            CouponExample.Criteria criteria = couponExample.createCriteria();
            criteria.andDeletedEqualTo(false);
            List<Coupon> coupons = couponMapper.selectByExample(couponExample);
            while(true){
                String random = RandomUtils.createSmallStrOrNumberRadom();
                for (Coupon coupon1 : coupons) {
                    if(random.equals(coupon1.getCode())) break;
                }
                coupon.setCode(random);
                break;
            }
        }else {
            coupon.setCode(null);
        }
        coupon.setTimeType(couponBo.getTimeType());
        coupon.setDays(couponBo.getDays());
        coupon.setStartTime(couponBo.getStartTime());
        coupon.setEndTime(couponBo.getEndTime());
        Date now = new Date(System.currentTimeMillis());
        coupon.setAddTime(now);
        coupon.setUpdateTime(now);
        coupon.setDeleted(false);
        return coupon;
    }


    public static CouponUserVo CouponUser2CouponUserVo(CouponUser couponUser){
        CouponUserVo couponUserVo = new CouponUserVo();
        couponUserVo.setId(couponUser.getId());
        couponUserVo.setUserId(couponUser.getUserId());
        couponUserVo.setCouponId(couponUser.getCouponId());
        couponUserVo.setStatus(couponUser.getStatus());
        couponUserVo.setStartTime(couponUser.getStartTime());
        couponUserVo.setEndTime(couponUser.getEndTime());
        couponUserVo.setAddTime(couponUser.getAddTime());
        couponUserVo.setUpdateTime(couponUser.getUpdateTime());
        couponUserVo.setDeleted(couponUser.getDeleted());
        return  couponUserVo;
    }

    public static TopicVo Topic2TopicVo(Topic topic){
        TopicVo topicVo = new TopicVo();
        topicVo.setId(topic.getId());
        topicVo.setTitle(topic.getTitle());
        topicVo.setSubtitle(topic.getSubtitle());
        topicVo.setPrice(topic.getPrice());
        topicVo.setReadCount(topic.getReadCount());
        topicVo.setPicUrl(topic.getPicUrl());
        topicVo.setSortOrder(topic.getSortOrder());
        topicVo.setAddTime(topic.getAddTime());
        topicVo.setUpdateTime(topic.getUpdateTime());
        topicVo.setDeleted(topic.getDeleted());
        topicVo.setContent(topic.getContent());
        topicVo.setGoods(topic.getGoods());
        return topicVo;
    }

    public static Topic TopicBo2Topic(TopicBo topicBo){
        Topic topic = new Topic();
        topic.setId(topicBo.getId());
        topic.setTitle(topicBo.getTitle());
        topic.setSubtitle(topicBo.getSubtitle());
        topic.setPrice(topicBo.getPrice());
        topic.setReadCount(topicBo.getReadCount());
        topic.setPicUrl(topicBo.getPicUrl());
        topic.setContent(topicBo.getContent());
        topic.setGoods(topicBo.getGoods());
        return topic;
    }

    public static GrouponRulesVo GrouponRules2GrouponRulesVo(GrouponRules grouponRule){
        GrouponRulesVo grouponRulesVo = new GrouponRulesVo();
        grouponRulesVo.setId(grouponRule.getId());
        grouponRulesVo.setGoodsId(grouponRule.getGoodsId());
        grouponRulesVo.setGoodsName(grouponRule.getGoodsName());
        grouponRulesVo.setPicUrl(grouponRule.getPicUrl());
        grouponRulesVo.setDiscount(grouponRule.getDiscount());
        grouponRulesVo.setDiscountMember(grouponRule.getDiscountMember());
        grouponRulesVo.setAddTime(grouponRule.getAddTime());
        grouponRulesVo.setUpdateTime(grouponRule.getUpdateTime());
        grouponRulesVo.setExpireTime(grouponRule.getExpireTime());
        grouponRulesVo.setDeleted(grouponRule.getDeleted());
        return grouponRulesVo;
    }

    public static GrouponRules GrouponRulesBo2GrouponRules(GrouponRulesBo grouponRulesBo){
        GrouponRules grouponRules = new GrouponRules();
        grouponRules.setId(grouponRulesBo.getId());
        grouponRules.setGoodsId(grouponRulesBo.getGoodsId());
        grouponRules.setGoodsName(grouponRulesBo.getGoodsName());
        grouponRules.setPicUrl(grouponRulesBo.getPicUrl());
        grouponRules.setDiscount(grouponRulesBo.getDiscount());
        grouponRules.setDiscountMember(grouponRulesBo.getDiscountMember());
        grouponRules.setAddTime(grouponRulesBo.getAddTime());
        grouponRules.setUpdateTime(grouponRulesBo.getUpdateTime());
        grouponRules.setExpireTime(grouponRulesBo.getExpireTime());
        grouponRules.setDeleted(grouponRulesBo.getDeleted());
        return grouponRules;
    }

    public static GrouponVo Groupon2GrouponVo(Groupon groupon){
        GrouponVo grouponVo = new GrouponVo();
        grouponVo.setId(groupon.getId());
        grouponVo.setOrderId(groupon.getOrderId());
        grouponVo.setGrouponId(groupon.getGrouponId());
        grouponVo.setRulesId(groupon.getRulesId());
        grouponVo.setCreatorUserId(groupon.getCreatorUserId());
        grouponVo.setAddTime(groupon.getAddTime());
        grouponVo.setUpdateTime(groupon.getUpdateTime());
        grouponVo.setPayed(groupon.getPayed());
        grouponVo.setDeleted(groupon.getDeleted());
        return grouponVo;
    }

    public static GoodsVo Goods2GoodsVo(Goods goods){
        GoodsVo goodsVo = new GoodsVo();
        goodsVo.setId(goods.getId());
        goodsVo.setGoodsSn(goods.getGoodsSn());
        goodsVo.setName(goods.getName());
        goodsVo.setCategoryId(goods.getCategoryId());
        goodsVo.setBrandId(goods.getBrandId());
        goodsVo.setGallery(goods.getGallery());
        goodsVo.setKeywords(goods.getKeywords());
        goodsVo.setBrief(goods.getBrief());
        goodsVo.setIsOnSale(goods.getIsOnSale());
        goodsVo.setSortOrder(goods.getSortOrder());
        goodsVo.setPicUrl(goods.getPicUrl());
        goodsVo.setShareUrl(goods.getShareUrl());
        goodsVo.setIsNew(goods.getIsNew());
        goodsVo.setIsHot(goods.getIsHot());
        goodsVo.setUnit(goods.getUnit());
        goodsVo.setCounterPrice(goods.getCounterPrice());
        goodsVo.setRetailPrice(goods.getRetailPrice());
        goodsVo.setAddTime(goods.getAddTime());
        goodsVo.setUpdateTime(goods.getUpdateTime());
        goodsVo.setDeleted(goods.getDeleted());
        goodsVo.setDetail(goods.getDetail());
        return goodsVo;
    }

    public static CatalogVo Category2CatalogVo(Category category){
        CatalogVo catalogVo = new CatalogVo();
        catalogVo.setId(category.getId());
        catalogVo.setName(category.getName());
        catalogVo.setKeywords(category.getKeywords());
        catalogVo.setDesc(category.getDesc());
        catalogVo.setPid(category.getPid());
        catalogVo.setIconUrl(category.getIconUrl());
        catalogVo.setPicUrl(category.getPicUrl());
        catalogVo.setLevel(category.getLevel());
        catalogVo.setSortOrder(category.getSortOrder());
        catalogVo.setAddTime(category.getAddTime());
        catalogVo.setUpdateTime(category.getUpdateTime());
        catalogVo.setDeleted(category.getDeleted());
        return catalogVo;
    }
}
